home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Browsers, Managers & Extensions / Flashgot 1.1.4 / flashgot-1.1.4.xpi / install.js < prev    next >
Text File  |  2008-11-13  |  5KB  |  132 lines

  1. const APP_DISPLAY_NAME = "FlashGot";
  2. const APP_NAME = "flashgot";
  3. const APP_PACKAGE = "/informaction/flashgot";
  4. const APP_VERSION = "1.1.4";
  5.  
  6. const APP_PREFS_FILE="defaults/preferences/flashgot.js";
  7. const APP_XPCOM_SERVICE="components/flashgotService.js";
  8. const APP_JAR_FILE = "flashgot.jar";
  9. const APP_CONTENT_FOLDER = "content/flashgot/";
  10. const APP_LOCALES = [
  11.   "it-IT","th-TH","de-DE","nl-NL", 
  12.   "ru-RU","es-ES","es-AR", "es-CL", // "ms-MY",
  13.   "hu-HU", "sv-SE","fr-FR", "fi-FI",
  14.   "he-IL","tr-TR","sr-YU", "ca-AD",
  15.   "zh-TW","zh-CN","el-GR", "uk-UA",
  16.   "lt-LT","ja-JP","pl-PL", "hr-HR",
  17.   "id-ID","cs-CZ","ko-KR", "be-BY",
  18.   "nb-NO","ro-RO","sk-SK",
  19.   "fa-IR","sl-SI","ar-JO",
  20.   "bg-BG","da-DK","pt-BR",
  21.   "pt-PT","sq-AL",
  22.   "am-HY","ar","ar-SA","hi-IN","km-KH",
  23.   "mn-MN","vi-VN","gl-ES",
  24.   "en-US" 
  25.   ];
  26.  
  27. const APP_SUCCESS_MESSAGE = APP_DISPLAY_NAME+" should now be available in your context menu when you restart Mozilla.";
  28.  
  29. const INST_TO_PROFILE = "Do you wish to install "+APP_DISPLAY_NAME+" to your profile?\nIf you are in doubt, this is the preferred option: click OK.\n(Click Cancel if you want "+APP_DISPLAY_NAME+" installing to the Mozilla directory.)";
  30.  
  31.  
  32. var instToProfile = true;
  33.  
  34. myPerformInstall(false);
  35.  
  36. function myPerformInstall(secondTry) {
  37.   
  38.   var err;
  39.   initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
  40.   
  41.   function chromeExistsIn(folder) {
  42.     var chrome = getFolder(folder, APP_JAR_FILE);
  43.     var isDir = File.isDirectory(chrome);
  44.     if (!isDir) isDir = /\/$/.test(chrome);
  45.     if (isDir)
  46.       File.dirRemove(chrome);  
  47.     return !chrome || !isDir;
  48.   }
  49.   
  50.   if(!secondTry) {  
  51.     // profile installs only work since 2003-03-06
  52.     instToProfile = chromeExistsIn(getFolder("Profile", "chrome")) ||
  53.       !chromeExistsIn(getFolder("chrome")) && 
  54.         buildID > 2003030600 && !!confirm(INST_TO_PROFILE);
  55.   }
  56.   
  57.   var chromef = instToProfile ? getFolder("Profile", "chrome") : getFolder("chrome");
  58.   err = addFile(APP_PACKAGE, APP_VERSION, "chrome/" + APP_JAR_FILE, chromef, null);
  59.   
  60.   if(APP_PREFS_FILE && (err == SUCCESS) ) {
  61.     const prefDirs=[
  62.       getFolder(getFolder("Profile"),"pref"),
  63.       getFolder(getFolder(getFolder("Program"),"defaults"),"pref")
  64.       ];
  65.     for(var j=prefDirs.length; j-->0;) {
  66.       var prefDir=prefDirs[j];
  67.       if(!File.exists(prefDir)) {
  68.         File.dirCreate(prefDir);
  69.       }
  70.       err = addFile(APP_PACKAGE, APP_VERSION,  APP_PREFS_FILE, prefDir, null, true);
  71.       logComment("Adding "+APP_PREFS_FILE+" in "+prefDir+": exit code = "+err);
  72.     }
  73.   }
  74.   
  75.   if(err == SUCCESS) {
  76.     var jar = getFolder(chromef, APP_JAR_FILE);
  77.     const chromeFlag=instToProfile?PROFILE_CHROME:DELAYED_CHROME;
  78.   
  79.     registerChrome(CONTENT | chromeFlag, jar, APP_CONTENT_FOLDER);
  80.     var localesCount=APP_LOCALES.length;
  81.     if(localesCount>0) {
  82.       registerChrome(LOCALE | chromeFlag, jar, "content/flashgot/"+APP_LOCALES[--localesCount]+"/");
  83.       while(localesCount-- >0) {
  84.         registerChrome(LOCALE  | chromeFlag, jar, "locale/"+APP_LOCALES[localesCount]+"/flashgot/");
  85.       }
  86.     }
  87.     registerChrome(SKIN | chromeFlag, jar, "skin/classic/flashgot/");
  88.     
  89.     
  90.     if(APP_XPCOM_SERVICE) {
  91.       var componentsDir = getFolder("Components");
  92.       /*
  93.       if (!(APP_XPCOM_SERVICE instanceof Array)) {
  94.         APP_XPCOM_SERVICE = [APP_XPCOM_SERVICE];
  95.       }
  96.       for (var s = APP_XPCOM_SERVICE.length; s-- > 0;)
  97.         addFile(APP_PACKAGE,APP_VERSION, APP_XPCOM_SERVICE[s], componentsDir, null, true);
  98.       */
  99.       addFile(APP_PACKAGE,APP_VERSION, APP_XPCOM_SERVICE, componentsDir, null, true);
  100.       addFile(APP_NAME, "components/.autoreg", getFolder("Program"), "");
  101.     }
  102.     
  103.     err = performInstall();
  104.     if(err == -239 && !secondTry) {
  105.       alert("Chrome registration problem, maybe transient, retrying...");
  106.       cancelInstall(err);
  107.       myPerformInstall(true);
  108.       return;
  109.     }
  110.     if(err == SUCCESS || err == 999) {
  111.       alert(APP_DISPLAY_NAME+" "+APP_VERSION+" has been succesfully installed in your " + 
  112.           (instToProfile ? "profile" : "browser") +
  113.           ".\n" + APP_SUCCESS_MESSAGE);
  114.     } else {
  115.       var msg = "Install failed!!! Error code:" + err;
  116.  
  117.       if(err == -239) {
  118.         msg += "\nThis specific error is usually transient:"
  119.           +"\nif you retry to install again, it will probably go away."
  120.       }
  121.  
  122.       alert(msg);
  123.       cancelInstall(err);
  124.     }
  125.   } else {
  126.     alert("Failed to create " +APP_JAR_FILE +"\n"
  127.       +"You probably don't have appropriate permissions \n"
  128.       +"(write access to your profile or chrome directory). \n"
  129.       +"_____________________________\nError code:" + err);
  130.     cancelInstall(err);
  131.   }
  132. }